package onlinebanking.client.gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ComboBoxEditor;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class LogoutPanel extends javax.swing.JPanel {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JButton SelectAccountButton;
	private JButton LogoutButton;
	private JComboBox AvailableAccounts;
	
	private ClientPanel parent;
	public JComboBox ActiveBADropdown;
	public JButton SelectActiveBAButton;


	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new LogoutPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public LogoutPanel() {
		super();
		initGUI();
	}
	
	public LogoutPanel(ClientPanel parent) {
		super();
		this.parent = parent;
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				this.setBounds(0, 0, 483, 100);
				this.setPreferredSize(new java.awt.Dimension(493, 50));
				this.setLayout(null);
				{
					SelectAccountButton = new JButton();
					this.add(SelectAccountButton);
					SelectAccountButton.setText("Select Bank Account");
					SelectAccountButton.setBounds(245, 13, 149, 22);
					SelectActiveBAButton = SelectAccountButton;
				}
				{
//					ComboBoxModel AvailableAccountsModel = 
//						new DefaultComboBoxModel(
//								new String[] { "Item One", "Item Two" });
					AvailableAccounts = new JComboBox();
					this.add(AvailableAccounts);
//					AvailableAccounts.setModel(AvailableAccountsModel);
					AvailableAccounts.setBounds(82, 13, 157, 22);
					AvailableAccounts.addItem("No Active Bank Accounts");
					SelectAccountButton.setEnabled(false);
					SelectAccountButton.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							SelectAccountButtonActionPerformed(evt);
						}
					});
					ActiveBADropdown = AvailableAccounts;
					

				}
				{
					LogoutButton = new JButton();
					this.add(LogoutButton);
					LogoutButton.setText("Log Out");
					LogoutButton.setBounds(403, 13, 84, 22);
					LogoutButton.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							LogoutButtonActionPerformed(evt);
						}
					});
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public void addBankAccountToDropDown(String accountNo){
		this.ActiveBADropdown.addItem(accountNo);
		this.SelectActiveBAButton.setEnabled(true);
	}
	
	public void clearBankAccountDropDown(){
		this.ActiveBADropdown.removeAllItems();
	}
	
	private void SelectAccountButtonActionPerformed(ActionEvent evt) {
		String accountno = (String)this.ActiveBADropdown.getSelectedItem();
		this.parent.getSimpleClient().selectActiveBankAccount(accountno);
	}
	
	private void LogoutButtonActionPerformed(ActionEvent evt) {
		this.parent.getSimpleClient().logout();
		this.parent.defaultModule();
	}
	
	

}
